package com.zkyc.framework.website.controller;

import com.zkyc.framework.common.exception.ResultCode;
import com.zkyc.framework.common.pojo.ApproveProcess;
import com.zkyc.framework.common.vo.ResultVO;
import com.zkyc.framework.common.vo.website.ApproveProcessPageVO;
import com.zkyc.framework.website.service.ApproveProcessService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * (ApproveProcess)表控制层
 *
 * @author libingchuan
 * @since 2023-02-15 16:21:27
 */
@RestController
@RequestMapping("approveProcess")
public class ApproveProcessController {
    /**
     * 服务对象
     */
    @Resource
    private ApproveProcessService approveProcessService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("listByPage")
    public ResultVO queryByPage(ApproveProcessPageVO approveProcessPageVo) {
        return approveProcessService.queryByPage(approveProcessPageVo);
    }
    
    /**
     * 查询
     *
     * @return 查询结果
     */
    @GetMapping("list")
    public ResultVO queryList() {
        return approveProcessService.queryList();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("query/{id}")
    public ResultVO queryById(@PathVariable("id") Integer id) {
        ApproveProcess approveProcess = approveProcessService.queryById(id);
        if(approveProcess == null){
            return ResultVO.fail(ResultCode.SERVE_ERROR);
        }
        return ResultVO.data(approveProcess);
    }

    /**
     * 新增数据
     *
     * @param approveProcess 实体
     * @return 新增结果
     */
    @PostMapping("save")
    public ResultVO add(@RequestBody ApproveProcess approveProcess) {
        return approveProcessService.insert(approveProcess);
    }

    /**
     * 编辑数据
     *
     * @param approveProcess 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    public ResultVO edit(@RequestBody ApproveProcess approveProcess) {
        return approveProcessService.update(approveProcess);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("delete")
    public ResultVO deleteById(Integer id) {
        return approveProcessService.deleteById(id);
    }

    /**
     * 初始化
     *
     * @return 是否成功
     */
    @GetMapping("init")
    public ResultVO init() {
        return approveProcessService.init();
    }


    /**
     * 判断身份
     *
     * @return 删除是否成功
     */
    @GetMapping("judgeIdentity")
    public ResultVO judgeIdentity() {
        return approveProcessService.judgeIdentity();
    }

    /**
     * 是否转二级
     *
     * @return 是
     */
    @GetMapping("isTransmit")
    public ResultVO isTransmit(Integer type) {
        return approveProcessService.isTransmit(type);
    }

}

